package clin.filesysclin;

import java.io.IOException;
import java.util.Scanner;

public class ConSocket {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("请输入目标主机IP：");
		String ip = sc.nextLine();
		SocCaozuo soc = new SocCaozuo();
		soc.setIp(ip);
		while (true) {
			try {
				System.out.print(">>");
				String str = sc.nextLine();
				if (str.equals("get as")) {
					System.out.println("總大小" + soc.getallsize() + "bit");
				} else if (str.equals("get ash")) {
					if (soc.getallsize() < 1024) {
						System.out.println("總大小" + soc.getallsize() + "bit");
					} else if (soc.getallsize() < 1024 * 1024 && soc.getallsize() >= 1024) {
						System.out.println("總大小" + soc.getallsize() / 1024 + "Kb");
					} else if (soc.getallsize() < 1024 * 1024 * 1024 && soc.getallsize() >= 1024 * 1024) {
						System.out.println("總大小" + soc.getallsize() / (1024 * 1024) + "Mb");
					} else if (soc.getallsize() >= 1024 * 1024 * 1024) {
						System.out.println("總大小" + soc.getallsize() / (1024 * 1024 * 1024) + "Gb");
					}
				} else if (str.equals("get us")) {
					System.out.println("已使用" + soc.getusedsize() + "bit");
				} else if (str.equals("get ush")) {
					if (soc.getusedsize() < 1024) {
						System.out.println("已使用" + soc.getusedsize() + "bit");
					} else if (soc.getusedsize() < 1024 * 1024 && soc.getusedsize() >= 1024) {
						System.out.println("已使用" + soc.getusedsize() / 1024 + "Kb");
					} else if (soc.getusedsize() < 1024 * 1024 * 1024 && soc.getusedsize() >= 1024 * 1024) {
						System.out.println("已使用" + soc.getusedsize() / (1024 * 1024) + "Mb");
					} else if (soc.getusedsize() >= 1024 * 1024 * 1024) {
						System.out.println("已使用" + soc.getusedsize() / (1024 * 1024 * 1024) + "Gb");
					}
				} else if (str.equals("get ub")) {
					System.out.println("已使用" + soc.getusedbaifenbi() + "%");
				} else if (str.equals("ls")) {
					soc.nowdir(false);
				}else if (str.equals("ls h")) {
					soc.nowdir(true);
				} else if (str.indexOf("rm") != -1) {
					soc.remfile(str.substring(3));
				} else if (str.indexOf("cd") != -1) {
					soc.qiehuandir(str.substring(3));
				} else if (str.indexOf("dir") != -1) {
					soc.createdir(str.substring(4));
				} else if (str.indexOf("add") != -1) {
					soc.addfile_loc(str.substring(4));
				} else if (str.indexOf("don") != -1) {
					String ss[] = str.split(" ");
					soc.getfile_loc(ss[1], ss[2]);
				} else if (str.equals("help")) {
					System.out.println("get as 獲取存儲體總大小");
					System.out.println("get ash 獲取存儲體總大小並轉化爲合適的單位顯示");
					System.out.println("get us 獲取已用空間大小");
					System.out.println("get ush 獲取已用空間大小並轉化爲合適的單位顯示");
					System.out.println("get ub 獲取已用空間佔用的百分比");
					System.out.println("ls 顯示當前目錄下的文件");
					System.out.println("ls h 顯示當前目錄下的文件,文件大小轉化爲合適的單位顯示");
					System.out.println("add [path] 上傳path路徑的文件");
					System.out.println("don [filename] [path] 下載filename文件到path目錄下(若此目錄下有和filename同名文件將會覆蓋)");
					System.out.println("rm [filename] 刪除filename文件");
					System.out.println("cd [path] 切換到path目錄下");
					System.out.println("dir [dirname] 創建目錄dirname");
					System.out.println("help 幫助");
				} else if (str.equals("exit")) {
					soc.exit();
					System.out.println("程序已退出");
					break;
				}else {
					System.out.println("無此指令");
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		sc.close();

	}

}
